//=============================================================================
// Shock Rifle
//=============================================================================
class LevGun extends Weapon
    config(user);

#EXEC OBJ LOAD FILE=InterfaceContent.utx

#exec OBJ LOAD FILE=..\Sounds\WeaponSounds.uax
#exec OBJ LOAD FILE=XEffectMat.utx
#exec OBJ LOAD FILE=UT2004Weapons.utx

var ShockProjectile ComboTarget; // used by AI
var bool   bRegisterTarget;
var bool   bWaitForCombo;
var vector   ComboStart;
var color   EffectColor;

var LevObject L;
var bool bPlayerControllerHasL;
var bool bWeaponHasL;

var class<DamageType> LevFireDamageType;

var LevManager LManager;

var float levManaTickCounter; //used in weapontick
const levManaTickDelay = 0.2;
const levManaTickDrain = 1;

function Tick(float dt){
    //initialization of LManager...if LManager isnt set yet, this syncs
    //it up with MPC's LManager. note: is this the right place to do this?
    if (Owner.Owner != none) {
      if (LManager == None || LManager != EnyaraPlayerController(self.Owner.Owner).LManager){
         LManager = EnyaraPlayerController(self.Owner.Owner).LManager;
      }
    }

    //check every tick if it has an object to lock onto
    /*if ( EnyaraPlayerController(self.Owner.Owner).hasK() ){
       self.hasL = true;
       self.L = EnyaraPlayerController(self.Owner.Owner).getL();
    }*/
    super.Tick(dt);
}

//sets the current damage type that should be used by LevFire (before dealing damage, LefFire
//checks the LevGun class for the damage type it should be using)
function setDType(class<DamageType> DType){
    self.LevFireDamageType = DType;
    self.LManager.printscreen("Damage Type Changed to"@self.LevFireDamageType);
}

function class<DamageType> getDType(){
    if (self.LevFireDamageType != none) return self.LevFireDamageType;
    else log("Error: getDamageType() called in LevGun class when LevFireDamageType was not set");
}

//called by LevFire to set the object to be levitated for LevGun and the PlayerController
function SetL( LevObject L ){
    local EnyaraPlayerController MPC;

    if (Owner.Owner != none) {
      MPC = EnyaraPlayerController(self.Owner.Owner);

      log("LEVGUN is checking if LMANAGER is in use...");
      if (! MPC.getLManager().isInUse()){
          log("...not in use");
          log("LEVGUN is calling LMANAGER.InitSetup()");
          MPC.getLManager().InitSetup(self, L);
          MPC.getLManager().logAttributes();

      } else {
          log("WARNING: you shouldnt be seeing this...LManager is already in use :(");
      }
    }

   /*
    self.L = L;
    self.bWeaponHasL = true;
    EnyaraPlayerController(self.Owner.Owner).setL(L);
    self.bPlayerControllerHasL = true;
    log("GET STATE name:"@L.GetStateName());
    */

}
//L's are unset when LevObject is no longer selected (on mouse release?)
function UnsetL(){
    LManager.InitTakedown();
}

//unset L's when firing stoped (mouse release)
simulated event StopFire(int Mode){
    if (Mode == 0) log("button released");
    //log("WEAPON OWNER"@self.Owner.name);
    //log(self.Owner.Owner.name);
    //log(EnyaraPlayerController(self.Owner.Owner).K.name);
    //log(hasKTarget);
    //if ( hasKTarget ) log("HAS KTARGET:"@KTarget.Name);
    /*if ( self.L != none){
       //log("STOPFIRE: PC.L"@EnyaraPlayerController(self.Owner.Owner).L.Name@"Weapon.L"@self.L.Name@"bWeapon"@self.bWeaponHasL@"bPC"@self.bPlayerControllerHasL);
       self.unsetL();
       //log("FINALSTATUS: PC.L"@EnyaraPlayerController(self.Owner.Owner).L.Name@"Weapon.L"@self.L.Name@"bWeapon"@self.bWeaponHasL@"bPC"@self.bPlayerControllerHasL);
    }*/
    if ( LManager.isInUse() ){
        log("clearing out LevManager");
        UnsetL();
       // LManager.logAttributes();
    }

    super.StopFire(Mode);
}


/*############################################################################
  #                    START Unmodified functions                            #
  ############################################################################*/
simulated function PostBeginPlay()
{
 ConstantColor'UT2004Weapons.ShockControl'.Color = EffectColor;
 super.PostBeginPlay();
}

simulated event RenderOverlays( Canvas Canvas )
{
 local float A;

 A = 128 * (1.0 - FMax(0,FMax((FireMode[0].NextFireTime - Level.TimeSeconds)/FireMode[0].FireRate,
        (FireMode[1].NextFireTime - Level.TimeSeconds)/FireMode[1].FireRate)));
 ConstantColor'UT2004Weapons.ShockControl'.Color.A = A;
 Super.RenderOverlays(Canvas);
}

simulated function vector GetEffectStart()
{
 local Coords C;

    if ( Instigator.IsFirstPerson() )
    {
  if ( WeaponCentered() )
   return CenteredEffectStart();
     C = GetBoneCoords('tip');
  return C.Origin - 15 * C.XAxis;
 }
 return Super.GetEffectStart();
}

simulated function bool WeaponCentered()
{
 return ( bSpectated || (Hand > 1) );
}
/*############################################################################
  #                    END Unmodified functions                              #
  ############################################################################*/

defaultproperties
{
    LevFireDamageType = class'Enyara.DamTypeLev';

    bPlayerControllerHasL = false
    bWeaponHasL = false

 HighDetailOverlay=Material'UT2004Weapons.WeaponSpecMap2'
    ItemName="Levitate"
    Description="The ASMD Shock Rifle has changed little since its incorporation into the Tournaments. The ASMD sports two firing modes capable of acting in concert to neutralize opponents in a devastating shockwave.||This combination attack is achieved when the weapon operator utilizes the secondary fire mode to deliver a charge of seeded plasma to the target.|Once the slow-moving plasma charge is within range of the target, the weapon operator may fire the photon beam into the plasma core, releasing the explosive energy of the anti-photons contained within the plasma's EM field."
    IconMaterial=Material'HudContent.Generic.HUD'
    IconCoords=(X1=250,Y1=110,X2=330,Y2=145)

    FireModeClass(0)=class'Enyara.LevFire'
    InventoryGroup=2
    Mesh=mesh'NewWeapons2004.ShockRifle'
    BobDamping=1.8
    PickupClass=class'ShockRiflePickup'
    EffectOffset=(X=65,Y=14,Z=-10)
    IdleAnim=Idle
    SelectAnim=Pickup
    PutDownAnim=PutDown

    DrawScale=0.7
    PlayerViewPivot=(Yaw=0,Pitch=-1000)
    PlayerViewOffset=(X=4,Y=8,Z=-2)
    SmallViewOffset=(X=11,Y=11.5,Z=-4)
    DisplayFOV=70
    SelectSound=Sound'WeaponSounds.ShockRifle.SwitchToShockRifle'
    AttachmentClass=class'ShockAttachment'
 SelectForce="SwitchToShockRifle"

 AIRating=+0.63
 CurrentRating=+0.63

    bDynamicLight=false
    LightType=LT_Steady
    LightEffect=LE_NonIncidence
    LightPeriod=3
    LightBrightness=255
    LightHue=200
    LightSaturation=70
    LightRadius=4.0

    HudColor=(r=128,g=0,b=255,a=255)
 CustomCrosshair=1
 CustomCrosshairTextureName="Crosshairs.Hud.Crosshair_Cross2"
 CustomCrosshairColor=(r=255,g=0,b=255,a=255)
 CustomCrosshairScale=+1.333
 Priority=30

 CenteredOffsetY=1.0
 CenteredYaw=-1000
 CenteredRoll=1000
 EffectColor=(r=192,g=0,b=255,a=128)
 OldMesh=mesh'Weapons.ShockRifle_1st'
    OldDrawScale=1.0
    OldPlayerViewOffset=(X=-15,Y=0,Z=-5)
    OldSmallViewOffset=(X=-8,Y=4,Z=-8)
    OldPlayerViewPivot=(Pitch=1000,Roll=-500,Yaw=-800)

 OldCenteredOffsetY=-8.0
 OldCenteredYaw=-500
 OldPickup="WeaponStaticMesh.ShockRiflePickup"
 bCanThrow=false;
}








